{% extends "configurarFaseLayout.html" %}
{% block subbodyfase %}
<script>
	function paginar(pagina){
		var filtro = document.form.filtro.value;
		window.location.href="abmItem?filtro="+filtro+"&pagina="+pagina+"&idfase="+ document.form.idfase.value;
	}
	function consultar() {
		var valor;
		if (document.form.check.value != null && document.form.check.checked) {
			valor = document.form.check.value;
		} else {
			for (i = 0; i < document.form.check.length; i++) {
				if (document.form.check[i].checked) {
					valor = document.form.check[i].value;
				}
			}
		}
		if (valor != null) {
			window.location.href = "consultarItem?iditem=" + valor
					+ "&filtro=" + document.form.filtro.value +"&idfase="+ document.form.idfase.value;
		} else {
			alert('Seleccionar un item');
		}
		  
	}
	function add() {
		window.location.href = "crearItem?filtro=" + document.form.filtro.value +"&idfase="+ document.form.idfase.value;
	}
	function graficarProyecto() {
		window.location.href = "verRelacionesProyecto";
	}
	function graficarFase() {
		window.location.href = "verRelacionesFase";
	}
	function graficarItem() {
		var valor;
		if (document.form.check.value != null && document.form.check.checked) {
			valor = document.form.check.value;
		} else {
			for (i = 0; i < document.form.check.length; i++) {
				if (document.form.check[i].checked) {
					valor = document.form.check[i].value;
				}
			}
		}
		if (valor != null) {
			window.location.href = "verRelacionesItem?&iditem=" + valor;
			 
		} else {
			alert('Seleccionar un item');
		}
	}
	function graficarFamiliaItem() {
		var valor;
		if (document.form.check.value != null && document.form.check.checked) {
			valor = document.form.check.value;
		} else {
			for (i = 0; i < document.form.check.length; i++) {
				if (document.form.check[i].checked) {
					valor = document.form.check[i].value;
				}
			}
		}
		if (valor != null) {
			window.location.href = "verFamiliaItem?&iditem=" + valor;
			
		} else {
			alert('Seleccionar un item');
		}
	}
	
	function revivir() {
		window.location.href = "revivirItem?idfase="+ document.form.idfase.value;
	}
	function edit() {
		var valor;
		if (document.form.check.value != null && document.form.check.checked) {
			valor = document.form.check.value;
		} else {
			for (i = 0; i < document.form.check.length; i++) {
				if (document.form.check[i].checked) {
					valor = document.form.check[i].value;
				}
			}
		}
		if (valor != null) {
			window.location.href = "modificarItem?iditem=" + valor
					+ "&filtro=" + document.form.filtro.value +"&idfase="+ document.form.idfase.value;
		} else {
			alert('Seleccionar un item');
		}
	}
	function del() {
		var valor;
		var filtro = document.form.filtro.value;

		if (document.form.check.value != null && document.form.check.checked) {
			valor = document.form.check.value;
		} else {
			for (i = 0; i < document.form.check.length; i++) {
				if (document.form.check[i].checked) {
					valor = document.form.check[i].value;
				}
			}
		}
		if (valor != null) {
			window.location.href = "eliminarItem?iditem=" + valor
				+ "&filtro=" + filtro +"&idfase="+ document.form.idfase.value;			
		} else {
			alert('Seleccionar un item');
		}
	}
	function aprobar() {
		var valor;
		if (document.form.check.value != null && document.form.check.checked) {
			valor = document.form.check.value;
		} else {
			for (i = 0; i < document.form.check.length; i++) {
				if (document.form.check[i].checked) {
					valor = document.form.check[i].value;
				}
			}
		}
		if (valor != null) {
			window.location.href = "aprobarItem?iditem=" + valor
					+ "&filtro=" + document.form.filtro.value +"&idfase="+ document.form.idfase.value;
		} else {
			alert('Seleccionar un item');
		}
		  
	}
	function restaurar() {
		var valor;
		if (document.form.check.value != null && document.form.check.checked) {
			valor = document.form.check.value;
		} else {
			for (i = 0; i < document.form.check.length; i++) {
				if (document.form.check[i].checked) {
					valor = document.form.check[i].value;
				}
			}
		}
		if (valor != null) {
			window.location.href = "restaurarItem?iditem=" + valor
					+ "&filtro=" + document.form.filtro.value +"&idfase="+ document.form.idfase.value;
		} else {
			alert('Seleccionar un item');
		}
		  
	}
	function atributos() {
		var valor;
		if (document.form.check.value != null && document.form.check.checked) {
			valor = document.form.check.value;
		} else {
			for (i = 0; i < document.form.check.length; i++) {
				if (document.form.check[i].checked) {
					valor = document.form.check[i].value;
				}
			}
		}
		if (valor != null) {
			window.location.href = "cargarAtributos?iditem=" + valor
					+ "&filtro=" + document.form.filtro.value +"&idfase="+ document.form.idfase.value;
		} else {
			alert('Seleccionar un item');
		}
		  
	}
	function adjuntar() {
		var valor;
		if (document.form.check.value != null && document.form.check.checked) {
			valor = document.form.check.value;
		} else {
			for (i = 0; i < document.form.check.length; i++) {
				if (document.form.check[i].checked) {
					valor = document.form.check[i].value;
				}
			}
		}
		if (valor != null) {
			window.location.href = "adjuntar?iditem=" + valor
					+ "&filtro=" + document.form.filtro.value +"&idfase="+ document.form.idfase.value;
		} else {
			alert('Seleccionar un item');
		}
	}
	
</script>
<body>
	<center>
		<div class="titulorojo">GESTIONAR ITEM</div>
	</center>
	<center>
		<form name="form" method="POST" action="abmItem">
			<input type="hidden" name="idproyecto" value="{{ idproyecto }}">
			<input type="hidden" name="idfase" value="{{ idfase }}">
			<table>
				<tr>
					<td class=titulochico>Filtro:</td>
					<td><input name=filtro size=20 maxlength=40
						value="{{ filtro }}"></td>
					<td><button onclick="submit">
							<img src="{{ url_for('static', filename='searching2.png') }}">
						</button></td>
					<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
					{% if '00040' in session["permisos"] %}
					<td><button type="button" onClick="consultar()">
							<img src="{{ url_for('static', filename='preview.png') }}">
						</button></td>
					{% endif %}
					{% if '00037' in session["permisos"] %}
					<td><button type="button" onClick="add()">
							<img src="{{ url_for('static', filename='add.png') }}">
						</button></td>
					{% endif %}
					{% if '00038' in session["permisos"] %}
					<td><button type="button" onClick="edit()">
							<img src="{{ url_for('static', filename='edit.png') }}">
						</button></td>
					{% endif %}
					{% if '00039' in session["permisos"] %}
					<td><button type="button" onClick="del()">
							<img src="{{ url_for('static', filename='delete.png') }}">
						</button></td>
					{% endif %}
					{% if '00041' in session["permisos"] %}
					<td><button type="button" onClick="aprobar()">
						Aprobar
					</button></td>
					{% endif %}
					{% if '00044' in session["permisos"] %}
					<td><button type="button" onClick="restaurar()">
						Restaurar
					</button></td>
					{% endif %}
					{% if '00045' in session["permisos"] %}
					<td><button type="button" onClick="atributos()">
						Atributos
					</button></td>
					{% endif %}
					{% if '00054' in session["permisos"] %}
					<td><button  type="button" onClick="adjuntar()">
							<img width="22px" heigth="22px" src="{{ url_for('static', filename='adjunto.png') }}">
						</button></td>
					{% endif %}
					
				</tr>
				<tr><td></td><td></td><td></td><td></td><td></td><td></td>
				<td></td><td></td>
				{% if '00046' in session["permisos"] %}
					<td><button type="button" onClick="revivir()">
						Revivir
					</button></td>
				{% endif %}
				</tr>
			</table>
			<br>
			<div>
			<table>
			<tr>
				<td><button type="button" onClick="graficarProyecto()">
					Graficar Proyecto
				</button></td>
				<td><button type="button" onClick="graficarFase()">
					Graficar Fase
				</button></td>
				<td><button type="button" onClick="graficarItem()">
					Graficar Relaciones de un Item
				</button></td>
				<td><button type="button" onClick="graficarFamiliaItem()">
					Graficar Familia de un Item
				</button></td>
			</tr>
			</table>
			</div>
			<br>
			<div>
			{% if cantPaginas >0 %}
			<a {% if pagina != primera  %} href="javascript:paginar({{ primera }})" {% endif %} style="text-decoration:none">[primera</a>/
			<a {% if ant >= 1 %} href="javascript:paginar({{ ant }})" {% endif %} style="text-decoration:none">anterior]</a>
			...
			{% if pagina - 2 >= primera %}
			<a href="javascript:paginar({{ pagina-2 }})" style="text-decoration:none">{{ pagina-2 }}</a>
			{% endif %}
			{% if pagina - 1 >= primera %}
			<a href="javascript:paginar({{ pagina-1 }})" style="text-decoration:none">{{ pagina-1 }}</a>
			{% endif %}
			{{ pagina }}
			{% if pagina + 1 <= ultima %}
			<a href="javascript:paginar({{ pagina+1 }})" style="text-decoration:none">{{ pagina+1 }}</a>
			{% endif %}
			{% if pagina + 2 <= ultima %}
			<a href="javascript:paginar({{ pagina+2 }})" style="text-decoration:none">{{ pagina+2 }}</a>
			{% endif %}
			...
			<a {% if sig <= cantPaginas %} href="javascript:paginar({{ sig }})" {% endif %} style="text-decoration:none">[siguiente</a>/
			<a {% if pagina != ultima  %} href="javascript:paginar({{ ultima }})" {% endif %} style="text-decoration:none">ultima]</a>
			{% endif %}
			</div>
			<table id="tabla" name="tabla" border=1 cellpadding=2 cellspacing=1
				width=70% align=center bgcolor=#E5E5E5>
				<tr>
					<th class=titulochico width='10%'>Numero</th>
					<th class=titulochico width='30%'>Nombre</th>
					<th class=titulochico width='20%'>Costo</th>
					<th class=titulochico width='20%'>Complejidad</th>
					<th class=titulochico width='20%'>Estado</th>
					<th class=titulochico width='10%'>Marcar</th>
				</tr>
				{% for item in lista : %}
				<tr>
				<td align=center>{{ item.numeroitem }}</td>
				<td align=center>{{ item.nombre }}</td>
				<td align=center>{{ item.costo }}</td>
				<td align=center>{{ item.complejidad }}</td>
				<td align=center>{{ item.estadoItem }}</td>
				<td align=center><input type="radio" name="check"
					value="{{ item.iditem }}"></td>
				</tr>
				{% endfor %}
			</table>
		</form>
	</center>
</body>
{% endblock subbodyfase %}
